• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About soitsthateasy

  • Rank
  1. SDL Key Presses (C++)

    I just started learning SDL from LazyFoo's tutorials and I'm trying to make a simple game of Tic-Tac-Toe. I made a console version a while ago so I want to make a graphical version now. I have a good idea of how to go about it, and I've worked out all the basic logic and functions now, Two things I need to work on: 1) How to find out where someone clicked on the screen. 2) How to write using fonts for the scoreboard (I believe that SDL can do that, could be wrong though...) So any help would be appreciated, thanks in advance!
  2. [web] Sign Up Page

    You'll need MySQL or some other database language for that. The basic idea is this: You have a form with username and password text boxes then you have a submit button for login and one for regestration. if(isset($_POST['registerButton']) ) //here goes all your mysql functions for cleaning the data and making new tables in the DB if(isset($_POST['loginButton']) ) //Here goes all your mysql functions for cleaning data and checking the cleaned data in the DB I found tizag a great place to learn mysql and PHP. W3Schools is also a great resource. If you're looking for a free web host that gives you access to databases, try 000webhost. 2 mysql databases, PHP and loads of other extras for free!
  3. Try messing around with the colspan="" attribute. I know it works for td but I'm not so sure about the rest of it...
  4. Linux Install Problems

    Dude! Worked like a charm :D ++rating;
  5. Linux Install Problems

    I actually am having some problems with fedora. My machine is 64-bit with 4 gigs of RAM. I shouldn't have any speed issues whatsoever but it's running ridiculously slow! It takes a good 20 seconds to load a web-page where it would normally load it in 5 or 6 seconds! Any fix?
  6. Linux Install Problems

    Thanks guys, I'm not the biggest fan of anything *buntu! I think I'll go with Fedora. I've got a live version of it on a usb key at the moment and I like it a lot. Thanks for yere help!
  7. Linux Install Problems

    I'm trying to install Debian 5.0.5 on my brand new gateway laptop but it complains about not being able to mount or read from the CD-ROM. I was talking to some people and they said that it might be because Debian isn't updated that regularly. This is getting really annoying now and I'm looking for some help. The BIOS is configured correctly but nothing I try is working! Any help appreciated!
  8. Starting College LapTop Suggestions???

    I bought my first laptop in America in some Radioshack (Them places are _so_ cool!) It's a Gateway NV54. 15.6" HD LED LCD screen, Intel Pentium Dual Core Processor speed of 2.20GhZ, 320 GB Hard Drive, 4 GB RAM, Webcam and Windows 7 Home Premium 64-bit. All for only $405! I got it at a discount however as it was the display model. If you're looking for _really_ cheap, look at those netbooks with no Hard Drives. Then buy a 1TB hard drive for ~100 euros.
  9. Accents

    In my opinion, accent is directly affected by topographical features surrounding you. Example: People from the Scottish Highlands speak with a clipped, rugged voice. The Scottish Highlands is a very rugged area of Scotland. People from Mid-America speak with a very flat accent. Mid-America is a very flat area with a lot of deserts and such (methinks). There are lots of examples of this. Too many to make it a coincidence...
  10. OO Tic-Tac-Toe and Snake (C++)

    Ok, something to work on for next time I suppose! Any other best practices or anything I should look at?
  11. OO Tic-Tac-Toe and Snake (C++)

    I had a week to myself with no internet and I ended up doing a lot of coding. I figured it was a good time to make a start on Object-Orientation but I had no book. I tried what I could remember and I think I made a good go off it but neither game (Tic-Tac-Toe and Snake) will work. With Tic-Tac-Toe, O ends up occupying all the spaces. Code here: #include <iostream> using std::cout; using std::cin; const char X='X'; const char O='O'; const char SPACE=' '; /********FOR CHECK WINNER FUNCTION********/ const char NONE='N'; const char DRAW='D'; class board { public: board() { for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { gameBoard[i][j]=SPACE; } } } void instructions() { cout<<"Tic-Tac-Toe\n"; cout<<"Enter your move according to the following:\n\n"; cout<<"0|1|2\n"; cout<<"3|4|5\n"; cout<<"6|7|8\n"; cout<<"\nTry to beat the computer!\n\n"; } void getPieces() { char choice; while(choice!='y' || choice!='n') { cout<<"Do you want to go first? (y)es or (n)o.\n"; cin>>choice; if(choice=='y') { human=X; computer=O; turn=X; break; } if(choice=='n') { human=O; computer=X; turn=X; break; } }//end of while loop } bool isLegal() { if(gameBoard[moveI][moveJ]==SPACE) { return true; } else { return false; } } void convertMove() { switch(move) { case 0: { moveI=0; moveJ=0; break; } case 1: { moveI=0; moveJ=1; break; } case 2: { moveI=0; moveJ=2; break; } case 3: { moveI=1; moveJ=0; break; } case 4: { moveI=1; moveJ=1; break; } case 5: { moveI=1; moveJ=2; break; } case 6: { moveI=2; moveJ=0; break; } case 7: { moveI=2; moveJ=1; break; } case 8: { moveI=2; moveJ=2; break; } default: { break; } }//End of switch... } void humanMove() { cout<<"\nEnter a number between 0 and 8.\n"; cin>>move; convertMove(); while(move>9 || move<0 || isLegal()==false) { convertMove(); cout<<"\nPlease enter a number between 0 and 8!\n"; cin>>move; } updateBoard(); } void changeTurn() { if(turn==human) turn=computer; else turn=human; } int computerMove() { int decided=0; if(decided==0) { {/*******IF COMPUTER CAN WIN, WIN************/ for(int i=0; i<3; i++) { for(int j=0; i<3; i++) { if(gameBoard[i][j]==SPACE) { gameBoard[i][j]=computer; if(checkWinner()==computer) { decided=1; moveI=i; moveJ=j; } if(checkWinner()!=computer) { gameBoard[i][j]=SPACE; } } } } } /*********IF HUMAN CAN WIN, BLOCK IT**********/ if(decided==0) { for(int i=0; i<3; i++) { for(int j=0; i<3; i++) { if(gameBoard[i][j]==SPACE) { gameBoard[i][j]=human; if(checkWinner()==human) { decided=1; gameBoard[i][j]=computer; moveI=i; moveI=i; moveJ=j; } if(checkWinner()!=human) { gameBoard[i][j]=SPACE; } } } } } /*******ELSE PICK NEXT BEST SQUARE********/ if(decided==0) if(gameBoard[1][1]==SPACE) { decided=1; gameBoard[1][1]=computer; } if(decided==0) if(gameBoard[0][0]==SPACE) { decided=1; gameBoard[0][0]=computer; } if(decided==0) if(gameBoard[0][2]==SPACE) { decided=1; gameBoard[0][2]=computer; } if(decided==0) if(gameBoard[2][0]==SPACE) { decided=1; gameBoard[2][0]=computer; } if(decided==0) if(gameBoard[2][2]==SPACE) { decided=1; gameBoard[2][2]=computer; } if(decided==0) if(gameBoard[0][1]==SPACE) { decided=1; gameBoard[0][1]=computer; } if(decided==0) if(gameBoard[1][0]==SPACE) { decided=1; gameBoard[1][0]=computer; } if(decided==0) if(gameBoard[1][2]==SPACE) { decided=1; gameBoard[1][2]=computer; } if(decided==0) if(gameBoard[2][1]==SPACE) { decided=1; gameBoard[2][1]=computer; } } if(decided==1) updateBoard(); } char checkWinner() { /***********CHECK FOR X WIN************/ for(int i=0; i<3; i++) if(gameBoard[i][0]==X && gameBoard[i][1]==X && gameBoard[i][2]==X) return X; for(int i=0; i<3; i++) if(gameBoard[0][i]==X && gameBoard[1][i]==X && gameBoard[2][i]==X) return X; if(gameBoard[0][0]==X && gameBoard[1][1]==X && gameBoard[2][2]==X) return X; if(gameBoard[2][0]==X && gameBoard[1][1]==X && gameBoard[0][2]==X) return X; /*********CHECK FOR O WIN************/ for(int i=0; i<3; i++) if(gameBoard[i][0]==O && gameBoard[i][1]==O && gameBoard[i][2]==O) return O; for(int i=0; i<3; i++) if(gameBoard[0][i]==O && gameBoard[1][i]==O && gameBoard[2][i]==O) return O; if(gameBoard[0][0]==O && gameBoard[1][1]==O && gameBoard[2][2]==O) return O; if(gameBoard[2][0]==O && gameBoard[1][1]==O && gameBoard[0][2]==O) return O; /***********CHECK FOR DRAW**********/ for(int i=0; i<3; i++) for(int j=0; j<3; j++) if(gameBoard[i][j]==SPACE) return NONE; return DRAW; } void printBoard() { cout<<gameBoard[0][0] <<"|" <<gameBoard[0][1] <<"|" <<gameBoard[0][2] <<"\n"; cout<<gameBoard[1][0] <<"|" <<gameBoard[1][1] <<"|" <<gameBoard[1][2] <<"\n"; cout<<gameBoard[2][0] <<"|" <<gameBoard[2][1] <<"|" <<gameBoard[2][2] <<"\n\n\n"; } void updateBoard() { if(turn==human) gameBoard[moveI][moveJ]=human; else gameBoard[moveI][moveJ]=computer; } void congratulate() { if(checkWinner()==human) { cout<<"\n\n\nCongratulations! You win!!!\n"; } if(checkWinner()==computer) { cout<<"\n\n\nToo Bad! You Lose!!!\n"; } if(checkWinner()==DRAW) { cout<<"\n\n\nIt's a draw! Well done!!!\n"; } } char getTurn() { return turn; } char getHuman() { return human; } char getComputer() { return computer; } private: char human; char computer; char gameBoard[3][3]; int move; int moveI; int moveJ; char turn; }; int main() { board game; game.instructions(); game.getPieces(); while(game.checkWinner()==NONE) { if(game.getTurn()==game.getHuman()) game.humanMove(); else game.computerMove(); game.printBoard(); game.changeTurn(); } game.congratulate(); system("PAUSE"); return 0; } Sorry about the dodgy indentation btw! In my Snake game, I think I remember reading somewhere that you can "peek" at the buffer. I figure that would be useful because at the moment, it needs input every iteration. Here's the code: #include <iostream> using std::cin; using std::cout; /******BOARD SET UP******/ const char SPACE=' '; const char WALL='@'; const char SNAKE='>'; const char FOOD='*'; /******DIRECTIONS*******/ const char UP='w'; const char DOWN='s'; const char LEFT='a'; const char RIGHT='d'; class snake { public: snake() { /*****BOARD SET UP*******/ for(int i=0; i<20; i++) for(int j=0; j<20; j++) board[i][j]=SPACE; for(int i=0; i<20; i++) board[i][0]=WALL; for(int i=0; i<20; i++) board[0][i]=WALL; for(int i=0; i<20; i++) board[i][19]=WALL; for(int i=0; i<20; i++) board[19][i]=WALL; /*****SNAKE SET-UP******/ for(int i=6; i<12; i++) board[9][i]=SNAKE; tailX=6; tailY=9; headX=11; headY=9; speed=1; score=0; move=RIGHT; } void getInput() { char input; cin>>input; if(input==UP || input==DOWN || input==LEFT || input==RIGHT) { if(move==UP && input==DOWN) move=move; if(move==DOWN && input==UP) move=move; if(move==LEFT && input==RIGHT) move=move; if(move==RIGHT && input==LEFT) move=move; else move=input; } } bool isLegal() { if(move==UP) if(board[headY-1][headX]==WALL || board[headY-1][headX]==SNAKE) return false; if(move==DOWN) if(board[headY+1][headX]==WALL || board[headY+1][headX]==SNAKE) return false; if(move==LEFT) if(board[headY][headX-1]==WALL || board[headY][headX-1]==SNAKE) return false; if(move==RIGHT) if(board[headY][headX+1]==WALL || board[headY][headX+1]==SNAKE) return false; return true; } void updateBoard() { if(isLegal()) { if(move==UP) { board[headY-1][headX]=SNAKE; headY-=1; /******SHORTEN SNAKE******/ if(board[tailY-1][tailX]==SNAKE) { tailY-=1; board[tailY][tailX]=SPACE; } if(board[tailY+1][tailX]==SNAKE) { tailY+=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX-1]==SNAKE) { tailX-=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX+1]==SNAKE) { tailX+=1; board[tailY][tailX]=SPACE; } } if(move==DOWN) { board[headY+1][headX]=SNAKE; headY+=1; /******SHORTEN SNAKE******/ if(board[tailY-1][tailX]==SNAKE) { tailY-=1; board[tailY][tailX]=SPACE; } if(board[tailY+1][tailX]==SNAKE) { tailY+=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX-1]==SNAKE) { tailX-=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX+1]==SNAKE) { tailX+=1; board[tailY][tailX]=SPACE; } } if(move==LEFT) { board[headY][headX-1]=SNAKE; headX-=1; /******SHORTEN SNAKE******/ if(board[tailY][tailX-1]==SNAKE) { tailX-=1; board[tailY][tailX]=SPACE; } if(board[tailY+1][tailX]==SNAKE) { tailY+=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX-1]==SNAKE) { tailX-=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX+1]==SNAKE) { tailX+=1; board[tailY][tailX]=SPACE; } } if(move==RIGHT) { board[headY][headX+1]=SNAKE; headX+=1; /******SHORTEN SNAKE******/ if(board[tailY-1][tailX]==SNAKE) { tailY-=1; board[tailY][tailX]=SPACE; } if(board[tailY+1][tailX]==SNAKE) { tailY+=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX-1]==SNAKE) { tailX-=1; board[tailY][tailX]=SPACE; } if(board[tailY][tailX+1]==SNAKE) { tailX+=1; board[tailY][tailX]=SPACE; } } score+=speed*5; } } void placeFood() { int randomY; int randomX; bool eaten=true; for(int i=0; i<20; i++) for(int j=0; j<20; j++) if(board[i][j]==FOOD) eaten=false; if(eaten) { score+=100; do { randomY=rand()%20+1; randomX=rand()%20+1; if(board[randomY][randomX]==SPACE) board[randomY][randomX]=FOOD; }while(board[randomY][randomX]!=FOOD); } } void displayBoard() { system("CLS"); for(int i=0; i<20; i++) { for(int j=0; j<20; j++) { cout<<board[i][j]; } cout<<"\n"; } cout<<"\nSCORE=" <<score <<"\n\n"; } private: char board[20][20]; int score; int speed; char move; int headX; int headY; int tailX; int tailY; }; int main() { snake game; bool exit; while(1) { game.getInput(); exit=game.isLegal(); if(exit) { game.placeFood(); game.updateBoard(); game.displayBoard(); } if(!exit) break; } game.displayBoard(); system("PAUSE"); return 0; } So if anyone wants to comment on the best practices and what I did wrong, I'm all ears!
  12. Hardware Hacking

    Hey, I'd like to get into hardware hacking but I'm not really sure how. Should I get a book on electronics? Should I just take apart random stuff? I presume there's some stuff that would be good to know before starting so I don't electrocute myself ;P If anyone would like to recommend things to get, topics to read or easy, beginner projects, I'm all ears! Thanks in Advance.
  13. I'm new to JQuery and AJAX. I've only been learning them for ~1 day. I'm trying to make a form where the user puts in the data, hits submit and ajax takes the data and ships it off to my PHP script. The PHP script writes the data to two separate files and then returns 'OK' on success or the error on failure. This should then be printed out accordingly and the form hidden. The input is being written to the file ok but it's everything after that that's not working. Here's the AJAX/JQuery script: &lt;html&gt; &lt;head&gt; &lt;title&gt;JQuery trials&lt;/title&gt; &lt;script type="text/javascript" src="http://notmyfault.comxa.com/trial/ajaxForm/jquery-1.2.6.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; $ (document).ready(function() { $("p.toggle").click(function() { $("p.intro").toggle("slow"); }); }); &lt;/script&gt; &lt;p class="intro" style="display:none;"&gt;Here's how it works: I have a couple of songs in my music library. I want to get more into music so if you have just heard a song or you want to tell me to listen to one, just add it here! </p> &lt;p class="toggle" style="text-align:center; border:1px solid #BBBBBB;"&gt;Hide/Show</p> <p>Here's my music library right now!</p> &lt;div class="library"&gt; &lt;div class="artists" style="float:left; width:100px; margin-bottom:20px;"&gt; &lt;?php include("artists.txt"); ?&gt; </div> &lt;div class="songs" style="float:left; width:100px; margin-bottom:20px;"&gt; &lt;?php include("songs.txt"); ?&gt; </div> </div> &lt;script type="text/javascript"&gt; // we will add our javascript code here $(document).ready(function(){ var result=' '; $("#ajax-form").submit(function(){ // 'this' refers to the current submitted form var str = $(this).serialize(); $.ajax({ type: "POST", url:"http://notmyfault.comxa.com/blog/widgetscblockedript.php", data: str, success: function(msg){ $("#note").ajaxComplete(function(event, request, settings){ if(msg == "OK") // Message Sent? Show the 'Thank You' message and hide the form { $ ("#fields").hide(); $ ("#note").html('Your song has been added. Thank you!'); } else { $ ("#ajax-form").html(msg); } }); } }); return false; }); }); &lt;/script&gt; &lt;br/&gt;&lt;br/&gt; &lt;div id="note" syle="clear:left;"&gt;</div> &lt;div id="fields" style="clear:left;"&gt; &lt;form id="ajax-form" method="POST" action="javascript:alert('Success?');"&gt; Artist: &lt;input type="text" name="artist" /&gt; &lt;br /&gt; &lt;br /&gt; Song: &lt;input type="text" name="song" /&gt; &lt;br /&gt; &lt;br /&gt; &lt;input type="submit" name="submit" value="Add Song" /&gt; &lt;/form&gt; </div> &lt;/body&gt; &lt;/html&gt; And here's the PHP script: &lt;?php $post = (!empty($_POST)) ? true : false; if($post) { $artist = stripslashes( htmlentities($_POST['artist']) ); $song = stripslashes( htmlentities($_POST['song'] ) ); $error = ''; // Check artist if(!$artist) { $error .= 'Please enter an artist.'; } if(!$song) { $error .= 'Please enter a song.'; } if(!$error) { $artistFile='artists.txt'; $songFile='songs.txt'; $artistFileHandle=fopen($artistFile, 'a') or die($error.='Server-Side Error'); $songFileHandle=fopen($songFile, 'a') or die($error.='Server-Side Error'); fwrite($artistFileHandle, "$artist\n") or die($error.='Server-Side Error'); fwrite($songFileHandle, "$song\n") or die($error.='Server-Side Error'); fclose($artistFileHandle) or die($error.='Server-Side Error'); fclose($songFileHandle) or die($error.='Server-Side Error'); if(!error) { echo "OK"; } }//end of file write loop else { echo $error; } } ?&gt; Thanks
  14. 000webhost is pretty good and it's free! As far as I remember, there's 3 MySQL databases, PHP, the works. Completely free too...
  15. [web] DHTML ULs?

    I don't know how you would do that in javascript but from what I know, JQuery would do the job for you ;P
  • Advertisement