collapse collapse

* Who's Online

  • Dot Guests: 78
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - spum789

Pages: [1]
1
C++ / Pointer's acting up
« on: February 23, 2011, 09:14:18 pm »
ok so i have declared a pointer to an object. when i declare the pointer everything is fine. The problem is when i try to use the pointer outside of the main function whether its for setting the value of one of the variables in the class(which is public). anyways here is the code

Code: C++
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Team {
  6. public:
  7.         int players;
  8.         string type;
  9.         string name;
  10.         Team() : players(15) {}
  11.         ~Team() {}
  12. };
  13.  
  14. Team newTeam;
  15.  
  16. Team* pp = &newTeam;
  17.  
  18. //this is the part where i get the error which is this decleration has not storage class or type specifier
  19. //also i still get the same error whether i use the "*" or not
  20. *pp->players = 7;
  21.  
  22. int main(void)
  23. {
  24.         // but when used down here it gives an error that says "operand of '*' must be a pointer
  25.          pp->players = 8;
  26.          cout << pp->players << endl;
  27.          int x = 5;
  28.          cout << x << endl;
  29.          int* px = &x;
  30.          cout << *px << endl;
  31.          *px = 7;
  32.          cout << *px << endl;
  33.          *px -= 2;
  34.          cout << *px << endl;
  35.          getchar();
  36. }

[edited name=spum789 date=1298517503][/edited]
[edited name=spum789 date=1298517620][/edited]

2
Challenges / Guessing Game submission
« on: November 16, 2009, 01:36:45 pm »
ok, this took no time at all. but i'm just getting these challenges out of the way so here it is

Code: C++
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool again = true;
  8. char play_again;
  9.  
  10. int main()
  11. {
  12.         do {
  13.         srand(GetTickCount());
  14.         int ran_num = rand()%11;
  15.         int user_guess;
  16.         cout << "Time to play a guessing game" << endl;
  17.         cout << "I'm going to guess a number between 0 and 10" << endl;
  18.         cout << "If you get it right then you'll win." << endl << endl << endl;
  19.         cout << "Enter you guess:";
  20.         cin >> user_guess;
  21.         if(user_guess == ran_num) {
  22.                 cout << "you win!" << "play again? y/n" << endl;
  23.                 cin >> play_again;
  24.                 if(play_again == 'y') {
  25.                         again = true;
  26.                         system("CLS");
  27.                 }
  28.                 else {
  29.                         again = false;
  30.                 }
  31.         }
  32.         else {
  33.                 cout << "you lose, try agian? y/n" << endl;
  34.                 cin >> play_again;
  35.                 if(play_again == 'y') {
  36.                         again = true;
  37.                         system("CLS");
  38.                 }
  39.                 else {
  40.                         again = false;
  41.                 }
  42.         }
  43.         }while(again == true);
  44.         getchar();
  45.         return 0;
  46. }
  47.        

3
Challenges / Simple AI challenge submission - Tic Tac Toe
« on: November 16, 2009, 12:22:25 am »
ok, so after about 2 days of failures, I have perfected my version of tic tac toe.
it comes with all the requirements of this challenge so download the .exe and play it

EDIT: i have posted the soucre because some ppl said that they'd like to see it, so here it is...again.

Code: C++
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. char box1;
  8. char box2;
  9. char box3;
  10. char box4;
  11. char box5;
  12. char box6;
  13. char box7;
  14. char box8;
  15. char box9;
  16. int user_move;
  17. int com_move;
  18. char comp_move;
  19. bool end_game;
  20. void game();
  21. string play_again;
  22.  
  23. void draw_board() {
  24.         cout << "[" << box1 << "]";
  25.         cout << "[" << box2 << "]";
  26.         cout << "[" << box3 << "]" << endl << endl;
  27.         cout << "[" << box4 << "]";
  28.         cout << "[" << box5 << "]";
  29.         cout << "[" << box6 << "]" << endl << endl;
  30.         cout << "[" << box7 << "]";
  31.         cout << "[" << box8 << "]";
  32.         cout << "[" << box9 << "]" << endl << endl;
  33. }
  34.  
  35. void bitch() {
  36.         cout << "Well it looks like your about to win." << endl;
  37.     Sleep(2000);
  38.         cout << "Not on my watch" << endl;
  39.         Sleep(2000);
  40.         cout << "Since i'm supposed to win every time, i'm going to be a bitch and do this" << endl;
  41.         Sleep(2000);
  42.         cout << "I WIN BITCH!!!!!!!!!!!!!!!!!" << endl;
  43.         Sleep(3000);
  44.         end_game = true;
  45. }
  46.  
  47. void com_AI() {
  48.         //regular AI
  49.         if(box1 == 'X' && box2 == 'X') {
  50.                 if(box3 == '3') {
  51.                         com_move = 3;
  52.                 }
  53.                 else {
  54.                         com_move = rand()%10;
  55.                 }
  56.         }
  57.         if(box2 == 'X' && box3 == 'X') {
  58.                 if(box1 == '1') {
  59.                         com_move = 1;
  60.                 }
  61.                 else {
  62.                         com_move = rand()%10;
  63.                 }
  64.         }
  65.         if(box1 == 'X' && box3 == 'X') {
  66.                 if(box2 == '2') {
  67.                         com_move = 2;
  68.                 }
  69.                 else {
  70.                         com_move = rand()%10;
  71.                 }
  72.         }
  73.         if(box4 == 'X' && box5 == 'X') {
  74.                 if(box6 == '6') {
  75.                         com_move = 6;
  76.                 }
  77.                 else {
  78.                         com_move = rand()%10;
  79.                 }
  80.         }
  81.         if(box5 == 'X' && box6 == 'X') {
  82.                 if(box4 == '4') {
  83.                         com_move = 4;
  84.                 }
  85.                 else {
  86.                         com_move = rand()%10;
  87.                 }
  88.         }
  89.         if(box4 == 'X' && box6 == 'X') {
  90.                 if(box5 == '5') {
  91.                         com_move = 5;
  92.                 }
  93.                 else {
  94.                         com_move = rand()%10;
  95.                 }
  96.         }
  97.         if(box7 == 'X' && box8 == 'X') {
  98.                 if(box9 == '9') {
  99.                         com_move = 9;
  100.                 }
  101.                 else {
  102.                         com_move = rand()%10;
  103.                 }
  104.         }
  105.         if(box8 == 'X' && box9 == 'X') {
  106.                 if(box7 == '7') {
  107.                         com_move = 7;
  108.                 }
  109.                 else {
  110.                         com_move = rand()%10;
  111.                 }
  112.         }
  113.         if(box7 == 'X' && box9 == 'X') {
  114.                 if(box8 == '8') {
  115.                         com_move = 8;
  116.                 }
  117.                 else {
  118.                         com_move = rand()%10;
  119.                 }
  120.         }
  121.         if(box1 == 'X' && box9 == 'X') {
  122.                 if(box5 == '5') {
  123.                         com_move = 5;
  124.                 }
  125.                 else {
  126.                         com_move = rand()%10;
  127.                 }
  128.         }
  129.         if(box1 == 'X' && box5 == 'X') {
  130.                 if(box9 == '9') {
  131.                         com_move = 9;
  132.                 }
  133.                 else {
  134.                         com_move = rand()%10;
  135.                 }
  136.         }
  137.         if(box5 == 'X' && box9 == 'X') {
  138.                 if(box1 == '1') {
  139.                         com_move = 1;
  140.                 }
  141.                 else {
  142.                         com_move = rand()%10;
  143.                 }
  144.         }
  145.         if(box3 == 'X' && box5 == 'X') {
  146.                 if(box7 == '7') {
  147.                         com_move = 7;
  148.                 }
  149.                 else {
  150.                         com_move = rand()%10;
  151.                 }
  152.         }
  153.         if(box5 == 'X' && box7 == 'X') {
  154.                 if(box3 == '3') {
  155.                         com_move = 3;
  156.                 }
  157.                 else {
  158.                         com_move = rand()%10;
  159.                 }
  160.         }
  161.         if(box3 == 'X' && box7 == 'X') {
  162.                 if(box5 == '5') {
  163.                         com_move = 5;
  164.                 }
  165.                 else {
  166.                         com_move = rand()%10;
  167.                 }
  168.         }
  169.         if(box1 == 'X' && box4 == 'X') {
  170.                 if(box7 == '7') {
  171.                         com_move = 7;
  172.                 }
  173.                 else {
  174.                         com_move = rand()%10;
  175.                 }
  176.         }
  177.         if(box1 == 'X' && box7 == 'X') {
  178.                 if(box4 == '4') {
  179.                         com_move = 4;
  180.                 }
  181.                 else {
  182.                         com_move = rand()%10;
  183.                 }
  184.         }
  185.         if(box4 == 'X' && box7 == 'X') {
  186.                 if(box1 == '1') {
  187.                         com_move = 1;
  188.                 }
  189.                 else {
  190.                         com_move = rand()%10;
  191.                 }
  192.         }
  193.         if(box2 == 'X' && box5 == 'X') {
  194.                 if(box8 == '8') {
  195.                         com_move = 8;
  196.                 }
  197.                 else {
  198.                         com_move = rand()%10;
  199.                 }
  200.         }
  201.         if(box5 == 'X' && box8 == 'X') {
  202.                 if(box2 == '2') {
  203.                         com_move = 2;
  204.                 }
  205.                 else {
  206.                         com_move = rand()%10;
  207.                 }
  208.         }
  209.         if(box2 == 'X' && box8 == 'X') {
  210.                 if(box5 == '5') {
  211.                         com_move = 5;
  212.                 }
  213.                 else {
  214.                         com_move = rand()%10;
  215.                 }
  216.         }
  217.         if(box3 == 'X' && box6 == 'X') {
  218.                 if(box9 == '9') {
  219.                         com_move = 9;
  220.                 }
  221.                 else {
  222.                         com_move = rand()%10;
  223.                 }
  224.         }
  225.         if(box6 == 'X' && box9 == 'X') {
  226.                 if(box3 == '3') {
  227.                         com_move = 3;
  228.                 }
  229.                 else {
  230.                         com_move = rand()%10;
  231.                 }
  232.         }
  233.         if(box3 == 'X' && box9 == 'X') {
  234.                 if(box6 == '6') {
  235.                         com_move = 6;
  236.                 }
  237.                 else {
  238.                         com_move = rand()%10;
  239.                 }
  240.         }
  241.         //perfect AI
  242.         //infamous "V" checks
  243.         if(box1 == 'X' && box5 == 'X' && box3 == 'X') {
  244.                 bitch();
  245.         }
  246.         else if(box1 == 'X' && box5 == 'X' && box7 == 'X') {
  247.                 bitch();
  248.         }
  249.         else if(box3 == 'X' && box5 == 'X' && box9 == 'X') {
  250.                 bitch();
  251.         }
  252.         else if(box7 == 'X' && box5 == 'X' && box9 == 'X') {
  253.                 bitch();
  254.         }
  255.         //infamous "C" checks
  256.         else if(box1 == 'X' && box3 == 'X' && box9 == 'X') {
  257.                 bitch();
  258.         }
  259.         else if(box3 == 'X' && box9 == 'X' && box7 == 'X') {
  260.                 bitch();
  261.         }
  262.         else if(box9 == 'X' && box7 == 'X' && box1 == 'X') {
  263.                 bitch();
  264.         }
  265.         else if(box7 == 'X' && box1 == 'X' && box3 == 'X') {
  266.                 bitch();
  267.         }
  268. }
  269.  
  270. void again() {
  271.         cout << "play again" << endl;
  272.         cin >> play_again;
  273.         if(play_again == "y") {
  274.                 cout << "ok" << endl;
  275.                 system("CLS");
  276.                 game();
  277.         }
  278.         else if(play_again == "n") {
  279.                 end_game = true;
  280.         }
  281. }
  282.  
  283. void game_over() {
  284.         //x's win conditions
  285.         if(box1 == 'X' && box2 == 'X' && box3 == 'X') {
  286.                 cout << "X's win" << endl;
  287.                 again();
  288.         }
  289.         else if(box4 == 'X' && box5 == 'X' && box6 == 'X') {
  290.                 cout << "X's win" << endl;
  291.                 again();
  292.         }
  293.         else if(box7 == 'X' && box8 == 'X' && box9 == 'X') {
  294.                 cout << "X's win" << endl;
  295.                 again();
  296.         }
  297.         else if(box7 == 'X' && box4 == 'X' && box1 == 'X') {
  298.                 cout << "X's win" << endl;
  299.                         again();
  300.         }
  301.         else if(box8 == 'X' && box5 == 'X' && box2 == 'X') {
  302.                 cout << "X's win" << endl;
  303.                 again();
  304.         }
  305.         else if(box9 == 'X' && box6 == 'X' && box3 == 'X') {
  306.                 cout << "X's win" << endl;
  307.                 again();
  308.         }
  309.         else if(box7 == 'X' && box5 == 'X' && box3 == 'X') {
  310.                 cout << "X's win" << endl;     
  311.                 again();
  312.         }
  313.         else if(box1 == 'X' && box5 == 'X' && box9 == 'X') {
  314.                 cout << "X's win" << endl;
  315.                 again();
  316.         }
  317.        
  318.         //o's win conditions
  319.         if(box1 == 'O' && box2 == 'O' && box3 == 'O') {
  320.                 cout << "O's win" << endl;
  321.                 again();
  322.         }
  323.         else if(box4 == 'O' && box5 == 'O' && box6 == 'O') {
  324.                 cout << "O's win" << endl;
  325.                 again();
  326.         }
  327.         else if(box7 == 'O' && box8 == 'O' && box9 == 'O') {
  328.                 cout << "O's win" << endl;
  329.                 again();
  330.         }
  331.         else if(box7 == 'O' && box4 == 'O' && box1 == 'O') {
  332.                 cout << "O's win" << endl;
  333.                 again();
  334.         }
  335.         else if(box8 == 'O' && box5 == 'O' && box2 == 'O') {
  336.                 cout << "O's win" << endl;
  337.                         again();
  338.         }
  339.         else if(box9 == 'O' && box6 == 'O' && box3 == 'O') {
  340.                 cout << "O's win" << endl;
  341.                         again();
  342.         }
  343.         else if(box7 == 'O' && box5 == 'O' && box3 == 'O') {
  344.                 cout << "O's win" << endl;
  345.                         again();
  346.         }
  347.         else if(box1 == 'O' && box5 == 'O' && box9 == 'O') {
  348.                 cout << "O's win" << endl;
  349.                 again();
  350.         }
  351. }
  352.  
  353. void game() {
  354.         box1 = '1';
  355.         box2 = '2';
  356.         box3 = '3';
  357.         box4 = '4';
  358.         box5 = '5';
  359.         box6 = '6';
  360.         box7 = '7';
  361.         box8 = '8';
  362.         box9 = '9';
  363.         draw_board();
  364.         cout << "To select a box, enter the corresponding number." << endl << "Your move:";
  365.         do {
  366.         cin >> user_move;
  367.         switch(user_move) {
  368.                 case 1:
  369.                         if(box1 == '1') {
  370.                                 box1 = 'X';
  371.                         }
  372.                         else {
  373.                                 cout << "invalid move" << endl;
  374.                         }
  375.                         break;
  376.                 case 2:
  377.                         if(box2 == '2') {
  378.                                 box2 = 'X';
  379.                         }
  380.                         else {
  381.                                 cout << "invalid move" << endl;
  382.                         }
  383.                         break;
  384.                 case 3:
  385.                         if(box3 == '3') {
  386.                                 box3 = 'X';
  387.                         }
  388.                         else {
  389.                                 cout << "invalid move" << endl;
  390.                         }
  391.                         break;
  392.                 case 4:
  393.                         if(box4 == '4') {
  394.                                 box4 = 'X';
  395.                         }
  396.                         else {
  397.                                 cout << "invalid move" << endl;
  398.                         }
  399.                         break;
  400.                 case 5:
  401.                         if(box5 == '5') {
  402.                                 box5 = 'X';
  403.                         }
  404.                         else {
  405.                                 cout << "invalid move" << endl;
  406.                         }
  407.                         break;
  408.                 case 6:
  409.                         if(box6 == '6') {
  410.                                 box6 = 'X';
  411.                         }
  412.                         else {
  413.                                 cout << "invalid move" << endl;
  414.                         }
  415.                         break;
  416.                 case 7:
  417.                         if(box7 == '7') {
  418.                                 box7 = 'X';
  419.                         }
  420.                         else {
  421.                                 cout << "invalid move" << endl;
  422.                         }
  423.                         break;
  424.                 case 8:
  425.                         if(box8 == '8') {
  426.                                 box8 = 'X';
  427.                         }
  428.                         else {
  429.                                 cout << "invalid move" << endl;
  430.                         }
  431.                         break;
  432.                 case 9:
  433.                         if(box9 == '9') {
  434.                                 box9 = 'X';
  435.                         }
  436.                         else {
  437.                                 cout << "invalid move" << endl;
  438.                         }
  439.                         break;
  440.                 default:
  441.                         cout << "ERROR!!!! try again" << endl;
  442.                         break;
  443.         }
  444.        
  445. rand:
  446.         srand(GetTickCount());
  447.         com_move = rand()%10;
  448.         if(com_move == 0) {
  449.                 goto rand;
  450.         }
  451.         com_AI();
  452.         switch(com_move) {
  453.                 case 1:
  454.                         if(box1 == '1') {
  455.                                 box1 = 'O';
  456.                         }
  457.                         else {
  458.                                 cout << "invalid move" << endl;
  459.                                 goto rand;
  460.                         }
  461.                         break;
  462.                 case 2:
  463.                         if(box2 == '2') {
  464.                                 box2 = 'O';
  465.                         }
  466.                         else {
  467.                                 cout << "invalid move" << endl;
  468.                                 goto rand;
  469.                         }
  470.                         break;
  471.                 case 3:
  472.                         if(box3 == '3') {
  473.                                 box3 = 'O';
  474.                         }
  475.                         else {
  476.                                 cout << "invalid move" << endl;
  477.                                 goto rand;
  478.                         }
  479.                         break;
  480.                 case 4:
  481.                         if(box4 == '4') {
  482.                                 box4 = 'O';
  483.                         }
  484.                         else {
  485.                                 cout << "invalid move" << endl;
  486.                                 goto rand;
  487.                         }
  488.                         break;
  489.                 case 5:
  490.                         if(box5 == '5') {
  491.                                 box5 = 'O';
  492.                         }
  493.                         else {
  494.                                 cout << "invalid move" << endl;
  495.                                 goto rand;
  496.                         }
  497.                         break;
  498.                 case 6:
  499.                         if(box6 == '6') {
  500.                                 box6 = 'O';
  501.                         }
  502.                         else {
  503.                                 cout << "invalid move" << endl;
  504.                                 goto rand;
  505.                         }
  506.                         break;
  507.                 case 7:
  508.                         if(box7 == '7') {
  509.                                 box7 = 'O';
  510.                         }
  511.                         else {
  512.                                 cout << "invalid move" << endl;
  513.                                 goto rand;
  514.                         }
  515.                         break;
  516.                 case 8:
  517.                         if(box8 == '8') {
  518.                                 box8 = 'O';
  519.                         }
  520.                         else {
  521.                                 cout << "invalid move" << endl;
  522.                                 goto rand;
  523.                         }
  524.                         break;
  525.                 case 9:
  526.                         if(box9 == '9') {
  527.                                 box9 = 'O';
  528.                         }
  529.                         else {
  530.                                 cout << "invalid move" << endl;
  531.                                 goto rand;
  532.                         }
  533.                         break;
  534.                 default:
  535.                         cout << "ERROR!!!! try again" << endl;
  536.                         goto rand;
  537.                         break;
  538.         }
  539.         system("CLS");
  540.         game_over();
  541.         draw_board();
  542.         }while(end_game == false);
  543. }
  544.  
  545. int main()
  546. {
  547.         char play;
  548.         cout << "Wanna play tic-tac-toe? y/n" << endl;
  549.         cin >> play;
  550.         if(play == 'y') {
  551.                 game();
  552.         }
  553.         else {
  554.                 cout << "Well fine then, don't click me if you don't want to play.....dousce" << endl;
  555.         }
  556.         return 0;
  557. }

4
C++ / tic-tac-toe game screwing up
« on: November 15, 2009, 03:37:47 pm »
ok so first off the vaule of user_move doesn't get reset and then the while loop has to have 2 inputs jsut to keep going so idk y its fucking up, i just need help

EDIT: for some gay reason this post wants the 8 in line 46 to be a smiley even when i disable them, so in line 46 wehre you see a weblink just imagnine an 8 plz.


Code: C++
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string box1[10];
  8. bool end_game = true;
  9. int end = 0;
  10.  
  11. void draw_board()
  12. {
  13.         cout << "[" << box1[1] << "]";
  14.         cout << "[" << box1[2] << "]";
  15.         cout << "[" << box1[3] << "]" << endl << endl;
  16.         cout << "[" << box1[4] << "]";
  17.         cout << "[" << box1[5] << "]";
  18.         cout << "[" << box1[6] << "]" << endl << endl;
  19.         cout << "[" << box1[7] << "]";
  20.         cout << "[" << box1[8] << "]";
  21.         cout << "[" << box1[9] << "]" << endl << endl;
  22. }
  23.  
  24. void game()
  25. {
  26.         system("CLS");
  27.         cout << "Instructions: to mark you place enter the number that is in that box." << endl << endl;
  28.         box1[1] = "7";
  29.         box1[2] = "8";
  30.         box1[3] = "9";
  31.         box1[4] = "4";
  32.         box1[5] = "5";
  33.         box1[6] = "6";
  34.         box1[7] = "1";
  35.         box1[8] = "2";
  36.         box1[9] = "3";
  37.         draw_board();
  38.         do
  39.         {
  40.                 int user_move = 0;
  41.                 cin >> user_move;
  42.                 if(user_move == 7) {
  43.                         box1[1] = "X";
  44.                         draw_board();
  45.                 }
  46.                 else if(user_move == 8 ) {
  47.                         box1[2] = "X";
  48.                         draw_board();
  49.                 }
  50.                 else if(user_move == 9) {
  51.                         box1[3] = "X";
  52.                         draw_board();
  53.                 }
  54.                 else if(user_move == 4) {
  55.                         box1[4] = "X";
  56.                         draw_board();
  57.                 }
  58.                 else if(user_move == 5) {
  59.                         box1[5] = "X";
  60.                         draw_board();
  61.                 }
  62.                 else if(user_move == 6) {
  63.                         box1[6] = "X";
  64.                         draw_board();
  65.                 }
  66.                 else if(user_move == 1) {
  67.                         box1[7] = "X";
  68.                         draw_board();
  69.                 }
  70.                 else if(user_move == 2) {
  71.                         box1[8] = "X";
  72.                         draw_board();
  73.                 }
  74.                 else if(user_move == 3) {
  75.                         box1[9] = "X";
  76.                         draw_board();
  77.                 }      
  78.                 cout << "again? yes = 0 no = 1" << endl;
  79.                 cin >> end;
  80.                 if(end == 0) {
  81.                         end_game = false;
  82.                 }
  83.                 else if(end == 1) {
  84.                         break;
  85.                 }
  86.                 cout << user_move;
  87.         }while(end_game == false);
  88. }
  89.  
  90. int main()
  91. {
  92.         char play;
  93.         cout << "Wanna play tic-tac-toe? y/n" << endl;
  94.         cin >> play;
  95.         if(play == 'y') {
  96.                 game();
  97.                 getchar();
  98.         }
  99.         else {
  100.                 cout << "Well fine then, don't click me if you don't want to play.....dousce" << endl;
  101.         }
  102.         return 0;
  103. }


[edited name=spum789 date=1258321183][/edited]
[edited name=spum789 date=1258321225][/edited]
[edited name=spum789 date=1258321383][/edited]

5
C++ / While loop not exiting
« on: November 13, 2009, 06:59:44 pm »
hey i have a while loop that refueses to exit even though the condition is false

Code: C++
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int choice;
  5. bool cont = true;
  6. char cont1;  
  7.  
  8. void choices() {
  9.         cout << "Enter 1 or 2" << endl;
  10.         cin >> choice;
  11.         switch(choice)
  12.         {
  13.                 case 1:
  14.                         cout << "you have chosen 1" << endl;
  15.                         break;
  16.                 case 2:
  17.                         cout << "you have chosen 2" << endl;
  18.                         break;
  19.                 default:
  20.                         cout << "Error: You did not choose a 1 or a 2... douscebag" << endl;
  21.                         break;
  22.         }
  23.        
  24.        
  25. }
  26.  
  27. int main()
  28. {
  29.         do {
  30.                 choices();
  31.                 cout << "Would you like to enter another number? 0/1" << endl;
  32.                 cin >> cont1;
  33.                 if(cont1 == 'y') {
  34.                         cont = true;
  35.                 }
  36.                 else {
  37.                         cont = false;//here the condition is set to false if something other than y is entered
  38.                 }
  39.         }while(cont = true); //since the condition is false then the loop should exit but it doesn't
  40.         return 0;
  41. }

6
C++ / Links for C++ tutorials in order
« on: November 12, 2009, 01:07:18 pm »
*NOTE* the purpose of this post is so you can quickly go to any 1 tutorial without having to search for it.
Also tutorials 8 and 29 do not exist because celestialkey decided not to make them so those tutorials will not have links.

[1] C++ First Program
http://celestialcoding.com/index.php?topic=9.0

Run code: http://celestialcoding.codepad.org/mtRzTuWO

[2] Talking With The Keyboard
http://celestialcoding.com/index.php?topic=10.0

Run Code: http://ideone.com/r4SNE4

[3] Onto While Loops!
http://celestialcoding.com/index.php?topic=11.0

Run code: http://ideone.com/uChOpH

[4] For Loops!
http://celestialcoding.com/index.php?topic=12.0

Run code: http://ideone.com/XSAP04

[5] Conditional Statements
http://celestialcoding.com/index.php?topic=13.0

[6] Calculations and operations
http://celestialcoding.com/index.php?topic=14.0

[7] Defines and Macros
http://celestialcoding.com/index.php?topic=15.0

[9] Fun with Functions
http://celestialcoding.com/index.php?topic=16.0

[10] Time for a review!
http://celestialcoding.com/index.php?topic=17.0

[11] Random Numbers
http://celestialcoding.com/index.php?topic=19.0

[12] Arrays
http://celestialcoding.com/index.php?topic=20.0

[13] Structures
http://celestialcoding.com/index.php?topic=21.0

[14] File I/O
http://celestialcoding.com/index.php?topic=22.0

[15] Recursion
http://celestialcoding.com/index.php?topic=100.0

[16] Ternary Operators
http://celestialcoding.com/index.php?topic=101.0

[17] Pointers
http://celestialcoding.com/index.php?topic=102.0

[18] Dynamic Memory
http://celestialcoding.com/index.php?topic=130.0

[19] Review
http://celestialcoding.com/index.php?topic=133.0

[20] Seducing The Console Window
http://celestialcoding.com/index.php?topic=138.0

[21] Our first Console Game... Well, with graphics at least
http://celestialcoding.com/index.php?topic=140.0

[22] Changing colors of Font and Background
http://celestialcoding.com/index.php?topic=141.0

[23] Experimentation with Buffers
http://celestialcoding.com/index.php?topic=144.0

[24] A Simple Maze
http://celestialcoding.com/index.php?topic=147.0

[25] Overloading Functions
http://celestialcoding.com/index.php?topic=148.0

[26] Templates and 'anything goes' variables
http://celestialcoding.com/index.php?topic=150.0

[27] Classes Part 1
http://celestialcoding.com/index.php?topic=151.0

[28] The next Part of our Classes tutorial
http://celestialcoding.com/index.php?topic=279.0

[29] Virtual Functions
http://celestialcoding.com/index.php?topic=1248

[30] Overloading Operations
http://celestialcoding.com/index.php?topic=285.0

[31] Friend's and how they can touch your privates
http://celestialcoding.com/index.php?topic=286.0

[32] Const Keyword
http://celestialcoding.com/index.php?topic=287.0

[33] Using the Extern keyword
http://celestialcoding.com/index.php?topic=318.0

[34] Implementing a Queue
http://celestialcoding.com/index.php?topic=320.0

[35] Implementing a Stack this time
http://celestialcoding.com/index.php?topic=323.0

[36] Linked lists
http://celestialcoding.com/index.php?topic=324.0

[37] Playing music or sounds
http://celestialcoding.com/index.php?topic=328.0

[38] Searching for Files
http://celestialcoding.com/index.php?topic=329.0

[39] Implementing a BubbleSort
http://celestialcoding.com/index.php?topic=343.0

[40] Simple Vector Rundown
http://celestialcoding.com/index.php?topic=349.0

[41] Function Pointers
http://celestialcoding.com/index.php?topic=350.0

[42] Array of Functions
http://celestialcoding.com/index.php?topic=352.0

[43] Using Singletons
http://celestialcoding.com/index.php?topic=361.0


[edited name=Celestialkey date=1258053371][/edited]

7
OpenGL / 5: Alpha blending
« on: August 11, 2009, 11:56:34 pm »
For this tutorial we're going to create 2 cubes, put the smaller one inside the bigger one and make the bigger cube transparent so we can see the other cube.

You'll notice first that we've added a second angle variable, this will be used for the second cube.
Next you'll see, glPushMatrix();. this is used to save a certain "scene". For our program we're creating 2 cubes. were also going to rotate them in different directions. So we need glPushMatrix(); to save the "settings" of the first cube. If we didn't have it and we tried to rotate the 2 different cubes then it would get messed up because OpenGL would take all of the glRotatef() calls and add them together. So with glPushMatrix(); we can make shapes unique.
NOTE** each call to glPush Matrix(); will have a corresponding call to glPopMatrix();

for the rest of the code i'll just use comments to explain.

Code: [Select]
#include <gl.h>
#include <glut.h>

GLfloat angle = 0.0;
GLfloat angle2 = 0.0;

void cube() {
glPushMatrix();
glRotatef(angle, 1.0,0.0,0.0);//rotate along the x-axis
glColor4f(0.0,1.0,0.0,1.0);/* since we're using alpha blending we need the alpha argument for glColor()
so we change the "3" to a "4" alpha is used for transparencies. and its graded from 0.0 to 1.0 were 0 is
                completely transparent and 1 is completely solid.
glutSolidCube(1);// create a small solid cube
glPopMatrix();// pop the save to start a new one
}

void cube2() {
glPushMatrix();
glRotatef(angle2, 0.0,1.0,0.0);//rotate along the y-axis
glColor4f(1.0,0.0,0.0,0.2);// same deal here except this alpha variable is .2 so that it is "see-through"

glutSolidCube(2);
glPopMatrix();
}

void display() {
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// add this to clear alpha stuff
glEnable(GL_BLEND);// enable blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// needed for blending
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);
cube();
cube2();
glutSwapBuffers();
angle ++;
angle2 ++;
glFlush();
}

void reshape(int w, int h) { // nothing new here
glViewport(0,0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);// we need RGBA and DEPTH for alpha
       // blending
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Spum Light");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

now we have to cubes that spin the opposite way. and one is transparent

8
LUA / 1: How to execute Lua files from C++
« on: August 11, 2009, 04:38:16 pm »
OK, so after that first lesson your probablly wondering "But how do i code in Lua?". I promise you after these 3 lessons we'll get right into coding with lua.

First copy and paste this code into notepad and title it hello.lua
save the file in then same directory as your main.cpp file in your project
Code: [Select]
print("hello world in lua!!!!!")
here is the C++ code.
Code: [Select]
#include <stdio.h>
#include <iostream>
using namespace std;

/*Because lua is mainly for "C" we need to include it as such.*/
extern "C" {
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}

/*this lua functiion makes a call to the lua interpreter. initializes it, runs the files that we need, and then closes it.*/
void lua() {
        /* these calls to lua are kinda tricky with the "L" but once you type them enough you'll get used to it
        so if you have a problem compiling lua ALWAYS check here first*/
lua_State* L;//call the lua interpreter
L = lua_open();//init lua
luaL_openlibs(L);//init lua libs
luaL_dofile(L, "hello.lua");//do lua files
lua_close(L);//close lua
}

int main (int argc, char** argv)
{
   lua();//call lua function
   cout << "Press enter to exit" << endl;
   getchar();//duh
   return 0;
}

9
LUA / 0: Using Lua with C++
« on: August 11, 2009, 04:27:29 pm »
Lua is a light weight scripting language. It can be used to manipulate variables with out have to change the source code of an application. This first lesson will be on how to get Lua set-up with your compiler.

If you know how to set-up includes and libraries then you can skip step one.

First thing's first, download the attached files.

When the download is finished, open a new project in MVC++. then goto "Tools" - "Options". Nest Expand Projects and Solutions. Click on VC++ directiories. and in the drop down box select Include files, and select the include folder in Lua/5.1/include. Then in the drop down box select library files and do the same for that except use the lib folder in lua/5.1/lib, click "ok". Now your Compiler knows where to find lua



NOTE** YOU'LL HAVE TO REPEAT THIS STEP EVERY TIME YOU CREATE A NEW PROJECT!!!!
then goto your project properties. Expand "Configuration Properties", Expand "C/C++" and click on "Code Generation" and Next to "Runtime Library" change "Multi-Threaded Debug (DLL)" to "Multi-threaded DLL". Now Expand "Linker", click "Input" and in the "Additional Discrepancies" type "lua5.1.lib". congrats now you can compile and run projects with lua.

Next lesson we'll cover how to use lua with C++.

10
OpenGL / 4: Rotation
« on: August 11, 2009, 01:31:46 am »
Hey, here we're going to take  a wire cube and rotate it by 1 degree and keep doing it. In this program we need double buffering so that we can see a smoother rotation of the cube. to do this we glutInitDisplayMode(GLUT_DOUBLE);. and we swap the buffers to keep updating with glutSwapBuffers();. Have fun. for excersies try rotatin lines or triangles or some other weird shape that you come up with.


Code: [Select]
#include <gl.h>
#include <glut.h>

GLfloat angle = 0.0; //set the angle of rotation

void cube (void) {
    glRotatef(angle, 1.0, 0.0, 0.0); //rotate on the x axis
    glRotatef(angle, 0.0, 1.0, 0.0); //rotate on the y axis
    glColor3f(1.0, 0.0, 0.0);
    glutWireCube(2);// draws a wire cube at the center of the screen

}

void display (void) {
    glClearColor (0.0,0.0,0.0,1.0);
    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity(); 
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    cube();
    glutSwapBuffers();//we swap the buffers here so we can see wat we drew.
    angle ++;// here we increment the angle by 1 so the cube keeps rotating
}

void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
    glMatrixMode (GL_MODELVIEW);
}

int main (int argc, char **argv) {
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE); //set up the double buffering so that cube runs smoother
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("A basic OpenGL Window");
    glutDisplayFunc (display);
    glutIdleFunc (display);//we use this to keep updating the screen otherwise we'd see no change
    glutReshapeFunc (reshape);
    glutMainLoop ();
    return 0;
}

11
Introductions / spum789 V2 intro
« on: August 11, 2009, 12:59:46 am »
hey, my name is Justin A.K.A. spum789. plz if you will ignore my first intoduction as it is not a reflection of myself. Anyways, I'm currently in the process of college and stuff. I love to play xbox and any other console game. I love to be challenged, and I'm very competitive. one of my passions is to live in Japan for 2 or so years to learn and understand their culture 1st hand. I watch anime to help with my Japanese. My fav food is Pizza. If i had to choose one female celebrity to date it would be Megan Fox. And i'm also into UFC. I'm a pretty decent programmer, my main languages are C++ and Blitz. My favorite scripting language is Lua. And i'm pretty decent at SDL and OpenGL. Well thx for taking the time to read my intro ^_^. c ya.

12
OpenGL / 3: Adding color/details on shapes
« on: August 11, 2009, 12:12:10 am »
ok so in the previous lesson we drew a square. Well hoepfully you guessed that OpenGL can draw more than just quadrilaterals. It can draw everything from single points to lines, to triangles, polygons, the whole nine yards. and to do this we just do - glBegin(GL_TRIANGLES) or glBegin(GL_LINES) or glBegin(GL_POLYGONS), etc. so now that that's out of the way, lets talk about adding color to our boring shapes. basically we're going to take the code from the previous lesson and add exactly one line to it!!!! wow thats simple right.


here is the revised section
Code: [Select]
void square() {
glColor3f(255.0,0.0,0.0);// Here we change the drawing color so everything we draw from here is going to
        //red until we specify otherwise!! the parameters are (Red, Green, Blue, Alpha), if you don't already know
        // alpha is use for transparencies.

glBegin(GL_QUADS);

glVertex3f(-1.0,-1.0,0.0);
glVertex3f(-1.0,1.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(1.0,-1.0,0.0);

glEnd();
}

13
OpenGL / 2: Creating Shapes
« on: August 10, 2009, 02:40:21 pm »
Ok people, you probably already guessed that detailed comments were in the code from last lesson ^_^. I forgot sorry, fail. But anyways we'll just move right along with our next lesson, Creating shpaes!!!

Bassically i'll just use comments to explain functions. ^_^. But i will not recomment parts that we've already covered.

Code: [Select]
#include <gl.h>
#include <glut.h>

//our square drawing funciton
void square (void) {
    glBegin(GL_QUADS); //this call tells OpenGL that we want to begin drawing quadrilaterals.
    //note that every call to glBegin() will have a corresponding call to glEnd().
   
    //here we list the vertexes of our square/quad. Also because we're drawing quads OpenGL will start a new quad
    // every 5th vertex. anyways, i'll break down the syntax. glVertex3f - glVertex means we want to list a vertex.
    // the "3" means we're going to draw in 3D and the "f" means that our values will be of type floats. If you don't
    // already know the values are the coordinates on our x,y,z graph. If you don't know about x,y,z graphs then
    // just google it and it should be real simple to understand
    glVertex3f(-1, -1, 0); //first corner at -0.5, -0.5
    glVertex3f(-1, 1, 0.0); //second corner at -0.5, 0.5
    glVertex3f(1, 1, 0); //third corner at 0.5, 0.5
    glVertex3f(1, -1, 0.0); //fourth corner at 0.5, -0.5
    glEnd(); //here is our corresponding glEnd(); It tells OpenGL that we're done drawing quads
}

//here again is our display function or our "scene".
void display (void) {
    glClearColor (0.0,0.0,0.0,1.0);
    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity();// don't worry about wat this does yet.
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // set our camera posistion
    square(); // make a call to our square function
    glFlush(); //and flush/push it to the screen
}

//this new function is activated when the user re-sizes the window.
void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h);// this is how we're currently viewing the window
    glMatrixMode (GL_PROJECTION); // this lets us play with the "camera"
    glLoadIdentity ();
    gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0); // This tells OpenGL to not draw anything to close or
    // to far
    glMatrixMode (GL_MODELVIEW);// switch back to drawing mode
}

int main (int argc, char **argv) {
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("A basic OpenGL Window");
    glutDisplayFunc (display);//callls our draw function
    glutReshapeFunc (reshape);// calls our reshape function when the window changes
    glutMainLoop ();
    return 0;
}

14
OpenGL / 1: Getting Started/downloading libraries and headers
« on: August 10, 2009, 02:11:28 pm »
Hey, this is going to be the start of very simple OpenGL tutorials. This first lesson we'll download the files needed to run compile and debug OpenGL. For these lessons we'll use the C++ programming language. To download the Files i'll include a attach link so you can download them. I'm going to assume that you know how to set-up OpenGL on your compiler. Once you've downloaded the files then lets run a test program to see if it worked. I'm going to give the code without any explanation, until the next lesson. Create a new console project and copy and paste this code into your compiler

Code: [Select]
#include <gl.h> //include the gl header file
#include <glut.h> //include the glut header file

void display (void) {
    glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
    glClear (GL_COLOR_BUFFER_BIT); //Clear teh Color Buffer (more buffers later on)
    glLoadIdentity();  //load the Identity Matrix
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
    glFlush(); //flush it all to the screen
}

int main (int argc, char **argv) {
    glutInit (&argc, argv); //initialize the program.
    glutInitDisplayMode (GLUT_SINGLE); //set up a basic display buffer (only singular for now)
    glutInitWindowSize (500, 500); //set whe width and height of the window
    glutInitWindowPosition (100, 100); //set the position of the window
    glutCreateWindow ("A basic OpenGL Window"); //set the caption for the window
    glutDisplayFunc (display); //call the display function to draw our world
    glutMainLoop (); //initialize the OpenGL loop cycle
    return 0;
}

15
BlitzPlus / [1]: The Basics
« on: February 16, 2009, 11:21:56 pm »
Hey everybody If your an ambitious programmer looking to make video games but don't have a full grasp on C++ then this language is perfect for you. This language(BlitzPlus) is game-specific and will get you through your first steps onto becoming a great "game devver" i'm going to attach a file that has the IDE BlitzPlus in it, i'm pretty sure it will work if not then post here and i'll fix it...... so enough of the intros lets start our first lesson "The Basics".

I'm going to list the commands we're going to be using in this lesson and along with their definition and syntax and its main use..... again if there is something that you don't understand post a reply to this topic and I will explain/fix it ASAP. so here it goes

Commands:

1). Graphics
Use: we use this command to go into a graphics mode this command is probably the most used command in BlitzPlus
                  [1]     [2]     [3]    [4]    [5]
SYNTAX: Graphics,width,height,type,mode
[1]: This is The actual command it tells the IDE that you want to go into graphics mode without it you can't have any kind of graphics
[2]: Obviously this is the width-in-pixels so if we were to put in 640 for this value then we would get a screen that is 640 pixels wide
[3]: this is the height as with the width this is the height of the screen in pixels
[4]: this is the type of screen that you want usually we want this value to be 16 a resizable window that has a name and an 'x' button
[5]: this is the mode put 1 for full screen, and 2 for an non-fullscreen 

2).SetBuffer
Use: this command tell your graphics card/screen what buffer to draw on.
                  [1]          [2]
SYNTAX: SetBuffer validbuffer()
[1]: Command to switch the current buffer to any validbuffer()
[2]: this can be any valid buffer such as the FrontBuffer() or BackBuffer(). we almost always want to use the BackBuffer() because it will prevent screen flickering

3).Global
Use: sets any valid variable weather it be of type int,string ($), or of type float (#). a global variable means that the variable can be used throughout the whole program and any function,control statement or anything really can use it, so if we had a function that took x and added it by 1 everytime it was called and then wanted to print the value after 5 times of it being added then the value of x would be 5 assuming the initial value was 0. but be carefull some variables you might want to keep local to a certain function or control statement.
                [1]       [2]
SYNTAX: Global valid-variable
[1]: the command to tell the program that the following variable is Global
[2]: a variable. defaultly the variable will be an interger (int.... a whole-number), but you can change it to be of type string( a variable used to hold text characters with this "$" ex. string1$, or of type float( a number that can have decimal places) use this sign "#" the same way you would declare a string..

4).While loop
Use: this is a control statement that only executes if the condition is met and keeps executing until the condition is either false or the condition is met
              [1]       [2]                [3]
SYNTAX: While condition..........Wend
[1]: command used to say "while this is true then do this"
[2]: this part is the condition to be tested for instance if we had a variable x of type int that equaled 5 ( x = 5 ) then we could use this statement While x < 10. so the program checks to see if x is less than 10 and if so then do what follows within the while.....wend loop
[3]: this is used to tell the program where this particular while loop ends other wise the program will not compile becuase the while loop technically doesn't end

5).Text
Use: this command is used to draw a text onto the screen using the current font(ways to load new fonts will be taught in a later lesson) and the current color(explained in the next in this lesson)
               [1] 2 3           [4]
SYNTAX: Text,x,y,text to be written/drawn
[1]: The actual command
[2]: the x coordinate location on the screen in pixels
[3]: the y coordinate location on the screen in pixels
[4]: this can be either a pre-determined text like a string variable or it can be used like this "text here". so Text,0,0,"text here"

6). Cls
Use: clears the screen ...hopefully self-explanitory SYNTAX: Cls

7). Color
Use: Changes the drawing color
               [1]  [2]   [3]   [4]
SYNTAX: Color,red,green,blue
[1]: The command
[2]: the amount of red to use between 0 for none to 255 a lot
[3]: the amount of green to use
[4]: the amount of blue to use
 
EXAMPLE Color,255,255,255 this changes the color to white. you have to figure out how this works cuz i really don't feel like explaining but if you want just red then color,255,0,0.. etc.....

8). Flip
Use: flips the current drawing buffer to see what is on the screen other wise you won't get real-time updates.

9). End
Use: ends the program

EXAMPLE CODE:
copy and paste this or type it into your text field

Code: [Select]
Global gwidth = 640
Global gheight = 480
Global string1$ = "Hello World I am a BlitzPlus program"

Graphics gwidth,gheight,16,2
SetBuffer BackBuffer()

While Not KeyHit(1)

Cls
Color 255,255,255
Text 0,0,string1$
Flip

Wend

End

and i'll post a link to download the full version of blitzplus later but for now download it through this site
http://www.blitzbasic.com/Products/blitzplus.php

16
BlitzBASIC / 1: Hello World
« on: December 17, 2008, 06:44:34 pm »
hey yall now that you have your IDE its time to start learning to code in Blitz Basic.
first off you want to tell your computer what size screen you want to deal with. to do that we use the command Graphics
for example
Graphics 640,480,16,2
look at that! no semicolon or anything aww that was so much simpilar than C++
ok so let me explain this tells the computer to make a screen 640 pixels wide and 480 pixels high. and the 16,2 tell it to to go full screen. 

now this next command is used to set all things that we put onto the screen onto the backbuffer which keeps the screen from flickering.
setbuffer backbuffer()
basically each video car has 2 buffers a front and a back. what we see is on the front but for our program we want to put everything on the backbuffer. now we'll be able to see this by using the flip command later on. just look for it ^_^..
 
now lets tell the computer what we want to do with our program
print "Hello World"
ok this says print the text Hello world onto the screen. simple right?

now we need to use the flip command in order to see what is on the backbuffer.
Flip
wow easy right

ok now we need to tell the screen to pause to see if we did the program right. to do this we use the wait key command
waitkey()

and finally we end our program
End

here is our code all together
oh and btw this language is not case sensitive but whenever u use commands it converts the certain letters to caps automatically. so if you typed graphics after u presses the space bar it would convert to Graphics.

Code: [Select]
Graphics 640,480,16,2

SetBuffer BackBuffer()

Print "Hello World"

Flip

WaitKey()

End

and there you have it just click on the rocket ship to build and run the code and you have your first program in BlitzBasic. feel free to modify the text like to say Hello Justin how was you day. but anyways good luck and i'll see you for the next tutorial on loops and we will make our first image.!!! ^_^

17
BlitzBASIC / Download BlitzBasic IDE
« on: December 17, 2008, 06:17:02 pm »
alright guys here i am with a really good treat for yall. this is the Intro to the tutorials to come. and the reason why its so good is becuz this is a game-specific programing language. its a lot easier to write simple games in and takes a lot less lines of code than C++. Even though this language is not as strong it is still great if your wanting to jump right in to game programing and design. so first off i am going to attach a couple of links. The first is going to be a BitTorrent which will allow you to download torrents and i am going to explain y. first off you need the Blitzbasic IDE and the only way to get the full version without paying is to get it through a torrent.
here is the BitTorrent link. this must be downloaded AND installed first.
[Edit]
now here is the IDE and this is what you will write and compile the programs in.
[Edit]
after bitTorrent has finished downloading that go to where it was put usually C\:downloads and then install it and your all set!!!!!

Edit - Nathan - Please no links to copyright material posted publicly. I live in the US and they are really tough on copyright law, sorry.

18
Beta Releases / My version of pong
« on: December 12, 2008, 12:35:06 pm »
hey everybody here is my version of pong. i was going to put this up sooner but i had some more bugs to work out and it took a while for me to figure out how to release my program. but anyways here it is and let me know what you think.

****EDIT*****
hey ya'll sorry bout the glitch i fixed it and i posted the new version up here. and the opponents paddle should be smarter as well.^_^

19
Introductions / spum789: like the only C# user.
« on: December 06, 2008, 11:19:05 am »
Hey ya'll wats up. Well basically my main language is C++ but i am learning C# and am posting tutorials on the site about C#. Also i am very determined at wat i do. so think of me as like the coolest person of like all time. later.

20
C# / 5: All loops and control statements.
« on: December 05, 2008, 11:39:49 pm »
Hey everybody for this lesson we are going to go over all kinds of loops for C# and how and why we would use them.
so let me start by explaining each loop and how they work. then i'll give an example program.

The while loop:
syntax. note* syntax is a word that means how a statement should be coded. ex. Console.WriteLine(""); each part of that statement is syntax. and if you ever get syntax errors it is probably becuz u left our or added to much of something.
syntax for the while loop is. while (condition) then ur code block. ex
Code: [Select]
while (intVar < 10)
{
     Console.WriteLine("variable is less than 10");
}

This loop will check the condition to see if it is true. then if it its true then the program will execute the the code block that follows. and it is not garenteed that the while loop will execute at least 1 time and it is possible for it to always execute resulting in an infanite error.

The Do while loop:
syntax.
Code: [Select]

do
{   
      Console.WriteLine("your number is less than 10");
}while(intYourNumber < 10);

The difference about this loop is that it is guaranteed to execute at least once, this is because it doesn't check to see if the condition is true until the end of the code. and then it decides weather it needs to loop. this is used like if a menu has to be printed. or if u want the code to be executed and then possibly be executed even more times. its very cool.

Also u can use loops inside of loops if you need to do so. i'll show you in an example program.
Code: [Select]
using System;

class Learning
{
public static void Main()
{
string strChoice;
int intChoice;
int variable1 = 15; // just go with it for now usually i would make a program to ask for a number but i think you can figure that out on ur own.

do //start of our loop
{
Console.WriteLine("How old are you?"); // question
strChoice = Console.ReadLine();
intChoice = Int32.Parse(strChoice); // get user input and conversion from type string to type int.
while (intChoice < 18) // first while statement. execute if user input is less than 18
{
Console.WriteLine("your not of legal age yet.");
break; // used to avoid the infinate loop to see what i'm talking about remove the break; and recompile and run.
}
while (intChoice >= 18) // second while statement. execute if user input is 18 or above
{
Console.WriteLine("Your 18 or over congratz");
break;
}
}while(variable1 < 0);// this condition is checked and if it was true then it would loop to the beginning of the do loop.
Console.Read(); // and our usuall ending brackets and statements.
}
}

Well here we use a do while loop and then insert another 2 while loops just for the hell of it. so there you have it. try and modify this program to do other things. and don't take the next lesson till you fully grasp this one and all previous ones.

21
C# / 4: switch statements and loops!
« on: December 05, 2008, 08:33:25 pm »
hey everybody its time for another lesson on C# programming language.
switch statements are used for a user to select a function depending upon the topic of it.
switch statements are a more organized version of multiple else if statements. and should be used if you have 4 or more choices.
so lets get straight to the coding
open up your Learning project and use this code
Code: [Select]
using System;

    class Learning
    {
        public static void Main()
        {
            string myInput;
            int myInt;

            begin: // this is a basic loop that tells the program to go back here if the program runs across the command "goto" followed by begin: .. pretty cool huh.

            Console.Write("Please enter a number between 1 and 3: ");
            myInput = Console.ReadLine(); // this is used to convert myInput from type string to type int which is needed for the switch statement.
            myInt = Int32.Parse(myInput);// code that actually converts it. this is the easiest way to get input just go with it.

            // switch with integer type
            switch (myInt) // the switch statement evaluates what was typed because we stored it into myInt. 
            {
                case 1: // then the statement goes here if the case "1" was typed and executes this code. note* we use a colon here not a semicolon.
                    Console.WriteLine("Your number is {0}.", myInt);
                    break; // break statements are used to exit the switch statement.
                case 2:
                    Console.WriteLine("Your number is {0}.", myInt);
                    break;
                case 3:
                    Console.WriteLine("Your number is {0}.", myInt);
                    break;
                default:
                    Console.WriteLine("Your number {0} is not between 1 and 3.", myInt);
                    break;
            }

            decide: // another loop

            Console.Write("Type \"continue\" to go on or \"quit\" to stop: "); these slashes are used to ignore the quotes and write them as actuall text..
            myInput = Console.ReadLine(); //because we've already converted myInput once we don't need to convert it again.

            // switch with string type
            switch (myInput) // another switch statement that asks the user if he wants to rerun the whole program.
            {
                case "continue": // if user typed continue here then the code goto begin; would be executed and the program will go to the begin: part of the program.
                    goto begin;
                case "quit":
                    Console.WriteLine("Bye."); // here if quit is typed then the program exits because when a break; statement is used then it tells the program that the user is done with the switch statement and to not execute switch anymore. .
                    break;
                default: // default is used just like else. so if nothing is typed then the switch statement goes here and then imediatly exits.
                    Console.WriteLine("Your input {0} is incorrect.", myInput);
                    goto decide;
            }
        }// since there is not Console.Read(); here then once the programs finishes with the last switch statement then the program ends.
    }             

22
C# / 3: Conditional statements(if, else if)
« on: December 05, 2008, 07:13:05 pm »
Hello and welcome to tutorial number three 3: Conditional statements(if, else if, switch)
For this lesson we are going to experiment with Conditional statements. well to start off with Con. Statements are used
for when you want the user to make a choice, and depending on that choice the program will execute a certian portion of code block. so if we wanted to ask the user if his favorite color was green and give a response depending on his answer then we would use a program with the "if" statement. because the if statement is used for basically one way or the other. and usually involves either 1 or 2 choices. without further ado lets get to coding.
Make a new project named Learning.
Code: [Select]
using System;// Don't forget to declare your namespace.

class Learning // class declaration
{
public static void Main() // Main function of our program.
{
    Console.WriteLine("Is your favorite colour green? yes or no?");
            string strChoice = Console.ReadLine();// variable declaration
    if (strChoice == "yes") // conditional statement if so basically saying if users input equals yes then execute this.
    {
    Console.WriteLine("Hey thats cool.");
    }
    else // conditional statement else basically meaning that if the statement above is not true. then execute this.
    {
    Console.WriteLine("Well I like green");
    }
    Console.Read(); // and our closing statements as usuall.
}
}
ok now lets dissect the program and how it operates. basically when we declared the vairable strChoice to be of type string is because it was necessary due to the fact that a string type is used to hold well a string of letters and/or characters. by the way when you declare a variable that has multiple words then you need to capitalize the first letter.
also i like to declare string varialbes like this strSomething just becuase it helps to keep track. back to the subject, when we declared it equal to Console.ReadLine(); it is because we needed to record the users input into that strChoice for later use.  we could also declare it like this string strChoice; then later when we needed to get the input of the user then set strChoice equal to Console.ReadLine();.

Now if we wanted to be able to chose more choices then the statement else if would come in handy. here is an example program of that.
Code: [Select]
using System;

class Learning
{
public static void Main()
{
string strChoice;
Console.WriteLine("What is your favorite color?");
strChoice = Console.ReadLine();
if (strChoice == "blue")//checks to see if user input equals blue if input does not equal blue then the console skips to the next code block
{
Console.WriteLine("Hey i like that color to!");
}
else if (strChoice == "red")// checks to see if user input equals red if input does not equal red then the console skips to the next code block
{
Console.WriteLine("Hey I like That color to!");
}
        else if (strChoice == "green")//checks to see if user intput equals green if input does not equal green then the console skips to the next code block
        {
        Console.WriteLine("Hey thats my favorite color to!!");
        }
        else // this block of code is run if none of the code blocks above are true.
        {
        Console.WriteLine("I didn't understand your favorite color.");
        }
        Console.Read(); // and our usuall closing brackets and statements.
}
}
i basically explained the uses of else if statements in the code itself using comment bars. i may have forgotten to mention if u use two slashes like this // then it tells the program to ignore this whole line after these slashes.
now in our next lesson we will work with switch statements and touch on loops which lets us run certain parts of code agian without having to rewrite them.

23
C# / 2: Operators(add, sub, mult, div)
« on: December 05, 2008, 04:50:09 am »
Hey everybody i'm back with my second tutorial on C#.
For this lesson we are going to be working with Mathematical operators (+, -, x or *, and /)
so lets get right to the code.
First create a new c# project and name it operators.
Code: [Select]
using System; //Namespace declaration

   class operators
   {
        public static void Main()
       {
        int x;    //these are our variables ( x, y, result) they are of type int because they are going to contain numbers
        int y;   // its like algebra. since these variables are all of type int then we could declare them as this. int x, y,
        x = 8;   //here we declare what x and y equal. so that the program knows what values to work with
        y = 5;
        Console.WriteLine("The addition of 8 and 5 equals {0}",x + y);/* now if you've used C++ before then this statement is like cout << "The addition of 8 and 5 equals " << x + y << endl; so in C# {0} is used to display a result or a string its actually a lot cooler and easier than typing all those << and >> signs. so moving on, then the computer calculates the result of x + y(8 + 5) and puts the result into {0} so the result is 13*/
        Console.Read();// used to pause the program
       }// and our final closing brackets. i may have forgotten to mention the curly brackets are used to tell the compiler where the actual code for execution is. and each culy bracket set must have an opening bracket and a closing bracket.
   }
and thats basically it. now for the other operators you can change the operation from x + y to like x - y or x * y. oh and if u want to use divison you have to change the types of x and y to type double like this.
double x;
double y;
that way the computer can deal with decimal places. in my next tutorial i will explain how to use loops and conditional statements to choose from the console screen what operators you would like to use. think of it as a calcualter. well 'til next time c ya.

24
C# / 1: Hello World
« on: December 04, 2008, 09:25:53 pm »
hey everybody this is the first tutorial on the programing language of C#.
First off you need a C# compiler. I recommend this one.
http://antechinus-c-editor.software.informer.com/download/
just copy and paste this link into your url bar.
after you get that installed then you will probably need to install .NET Framework SDK.
download this via this link.http://www.microsoft.com/downloads/thankyou.aspx?familyId=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displayLang=en
(this step is after you install you compiler and the .NET thing.)
then whenever you go to compile the code you will need to designate a folder that the NMAKE.exe(this happens whenever you click on the compile button.) is so make sure you remember where you put the .NET SDK thing at. and it should be under Microsoft.NET Then under SDK then under Bin then you just scroll down to NMAKE.exe. then click on it. then click on the save as default button on the screen.
ok after that you should be good to go. and ready to start coding your first program in C#.
start off with this code
Code: [Select]
using System;

class Hello world // Class **** is used to identify the program and whatever u name ur project/program you name the //class exactly that
{
static void Main() // This is where the program starts to execute.
{
Console.Write("Hello world");// if you have ever use C++ then Console.Write("text here"); is just like cout << "text here" << endl; basically meaning it prints the text int the quotes onto the screen.
Console.Read();// this is just to keep the program open so u can see that it worked. so the program will end only when u press a key then enter.
}
}

Pages: [1]

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]